//
//  AfanMainTabBar.swift
//  weiboOfAfan
//
//  Created by afan on 16/3/19.
//  Copyright © 2016年 阿范. All rights reserved.
//

import UIKit


let TabBarItemCount = 5

class AfanMainTabBar: UITabBar {

    override func layoutSubviews() {
        super.layoutSubviews()
     
        let width = frame.width / CGFloat(TabBarItemCount)
        var index = 0
        for view in subviews{

            if view.isKindOfClass(NSClassFromString("UITabBarButton")!){
                view.frame = CGRect(x: CGFloat(index) * width, y: 0, width: width, height: frame.height)
                index += index == 1 ? 2 : 1
            }
        }
        addBut.frame = CGRect(x: 2 * width, y: 0, width: width, height: frame.height)
    }

    //MARK: - 懒加载
    private lazy var addBut :UIButton = {
        let btn = UIButton()
        
        btn.setBackgroundImage(UIImage(named: "tabbar_compose_button"), forState: UIControlState.Normal)
        btn.setBackgroundImage(UIImage(named: "tabbar_compose_button_highlighted"), forState: UIControlState.Highlighted)
        
        btn.setImage(UIImage(named:"tabbar_compose_icon_add"), forState: UIControlState.Normal)
        btn.setImage(UIImage(named: "tabbar_compose_icon_add_highlighted"), forState: UIControlState.Highlighted)
        
        self.addSubview(btn)
        
        return btn
    }()
}
